#include <my_head.h>

// 主机字节序转网络字节序 4字节
int func(int old_data){
    short flag= 0x1234;
    char *p = (char *)&flag;
    if(0x34 == *p){ // 小
        char *test_p = (char *)&old_data;
        char *test_q = test_p + 3;
        char temp = *test_p;
        *test_p = *test_q;
        *test_q = temp;
        test_p++;
        test_q--;
        temp = *test_p;
        *test_p = *test_q;
        *test_q = temp;
    }
    return old_data;
}

int main(int argc, const char *argv[]){
    int test_num = 0x12345678;
    int ret = func(test_num);
    printf("ret = %#x\n", ret); 
    //小端:0x78563412   大端:0x12345678
    return 0;
}